const checkout = {
    checkNum (rule, val) {
        if (rule.max && rule.min) {
            return (val.length < rule.max && val.length > rule.min)
        } else if (rule.min) {
            return val.length > rule.min
        } else if (rule.max) {
            return val.length < rule.max
        }
    },
    checkReg (rule, val) {
        window.console.log(rule, val, '=============')
        return rule.test(val)
    },
    checkRequired (rule, val) {
        window.console.log(val)
        if (!rule || val.length > 0) {
            window.console.log(8888)
            return true
        }
    },
    checkInit (rules, value) {
        // Object.keys(rules).forEach(() => {
        //     this.rules.forEach(prop => {
        //         window.console.log(rules[prop], prop, '666')
        //         if (rules[prop] !== undefined) {
        //             // window.console.log(prop)
        //             switch (prop) {
        //                 case 'required':
        //                     this.checkRequired(rules[prop])
        //                     break
        //                 case prop === 'max' || prop === 'min':
        //                     this.checkNum(rules[prop])
        //                     break
        //                 case prop === 'reg':
        //                     this.checkReg(rules[prop])
        //                     break
        //             }
        //         }
        //     })
        // })
        window.console.log(rules, value)
        let tempArr = Object.keys(rules)
        let ruleArr = this.rules.filter(val => tempArr.indexOf(val) !== -1)
        ruleArr.forEach(() => {
            this.rules.forEach(prop => {
                window.console.log(rules[prop])
                if (rules[prop] !== undefined) {
                    window.console.log(prop)
                    switch (prop) {
                        case 'required':
                            this.flog = this.checkRequired(rules[prop], value)
                            break
                        case 'max' || 'min':
                            this.flog = this.checkNum(rules, value)
                            break
                        case 'reg':
                            window.console.log(88888888888)
                            this.flog = this.checkReg(rules[prop], value)
                            break
                    }
                }
            })
        })
        return this.flog
    },
    rules: ['required', 'max', 'min', 'reg'],
    flog: undefined
}

export default checkout
